package com.example.healkep;

import static com.example.healkep.utils.MD5.MD5Encode;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.content.Intent;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import org.json.JSONObject;

import java.util.Objects;

import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class RegisterActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        EditText usernametext = findViewById(R.id.textView);
        EditText passwordtext = findViewById(R.id.textView2);
        Button register;
        register = findViewById(R.id.button);
        register.setOnClickListener(v -> {
            String username = usernametext.getText().toString();
            String password = passwordtext.getText().toString();
            password = MD5Encode(password);
            String finalPassword = password;
            String json = "{\n" +
                    "    \"username\":\"" + username + "\",\n" +
                    "    \"password\":\"" + finalPassword + "\",\n" +
                    "    \"role\":\"" + 1 + "\"\n" +
                    "}";
            Intent intent = new Intent(RegisterActivity.this,CaptchaRActivity.class);
            Bundle bundle = new Bundle();
            bundle.putString("json",json);
            bundle.putString("username",username);
            intent.putExtras(bundle);
            startActivity(intent);
        });
    }
}